<!DOCTYPE html>
<html>
<head>
	<title>NexHome</title>
    
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	
    <!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <!--<link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />-->

    <!-- libraries -->
   <link href="css/lib/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
    <link href="css/lib/font-awesome.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/layout.css" />
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
	<link rel="stylesheet" href="css/bootstrap-table.css"> 
    <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/index.css" type="text/css" media="screen" /> 
	<link rel="stylesheet" href="css/clean.css" type="text/css" media="screen" />    
	 
    <!-- open sans font -->
    <link href='css/OpenSans.css' rel='stylesheet' type='text/css' />

    <!-- lato font -->
    <link href='css/Lato.css' rel='stylesheet' type='text/css' />
	
<!--[if lt IE 9]>
      <script src="js/html5.js"></script>
    <![endif]-->     
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
	a{cursor:pointer;
	text-decoration: none;}
	</style>
</head>
<body>
    <div class="content" >   
        <div class="container-fluid">
         <div id="pad-wrapper" class="users-list">

               <div class="row-fluid header">
                    <h3>工程商列表&nbsp;&nbsp;&nbsp;<a id="ViewAllbtn"><i class="icon-refresh"></i></a></h3>
                    <div class="span10 pull-right" >
						<input type="text" class="span5" style="margin: 0;padding: 2px 6px;"  id="SearchUserTxt" placeholder="输入工程商名称或账号" onkeydown="return entersearch(event);" />
						<a id="cleanBtn" onclick="cleanIput()" style="position: relative; margin:-25px -25px;color: #9ba8b6"><i class="icon-search"></i></a>
						&nbsp;
						<div class="ui-dropdown" style="margin: 0px 31px">
                            <div class="head" data-toggle="tooltip" title="Click me!" id="SearchUserbtn">
                                用户筛选
                               
                            </div>  
                            
                           
                        </div>
						<a class="btn-flat danger" id="DeleteUserbtn" style="float:right; margin-left:10px;"><i class="icon-remove"></i>删除用户</a>&nbsp;&nbsp;
                        <a  onClick="JumpTOCreatuserPage();" class="btn-flat success pull-right">
                            <span>&#43;</span>
                            创建用户
                        </a>
						
                    </div>
                </div>
				<div class="table-wrapper table-products" style="margin-top:10px;">
				<div class="row-fluid table">
					<table id="table"   ></table>
				</div>
				</div>
				<div class="table-wrapper" style=" margin-bottom::10px;">
					
					
				 </div>
            </div>
        </div>
</div>
<div class="modal small hide fade" id="userMngModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">账户管理</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form id="userMngform">
					<table>	
						<tr><td>ID</td><td><input type="text" id="userMnguserid" name="userMnguserid"  class="input-xlarge" readonly ></td></tr>					
						<tr><td>用户名</td><td><input type="text" id="userMngusername" name="userMngusername"  class="input-xlarge" ></td></tr>
						<tr><td>密码</td><td><input type="text" id="userMngpwd"  name="userMngpwd"  class="input-xlarge" ></td></tr>
						<tr><td>工程商名称</td><td><input type="text" id="userMngprojectname" name="userMngprojectname"  class="input-xlarge" ></td></tr>						
						<tr><td>备注</td><td><textarea  id="userMngprojectinfo"  name="userMngprojectinfo" rows="3" class="input-xlarge"></textarea></td></tr>
						</table>					
					</form>
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="userMngModalbtn">修改</button>
				</div>
</div>
<div class="modal small hide fade" id="userDeleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">删除账户</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>将删除全部已选账户，是否确认删除？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="userDeleteModal_delbtn">删除</button>
				</div>
</div>
<div class="modal small hide fade" id="DelOneUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">删除账户</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>将删除该账户，是否确认删除？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="DelOneUserModal_delbtn">删除</button>
				</div>
	</div>
	
	<!-- scripts -->
	<script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery-latest.js"></script>
    <script src="js/bootstrap.min.js"></script>
	<script src="js/table/bootstrap-table.js"></script>
<script src="js/table/bootstrap-table-zh-CN.js"></script>
    <script src="js/jquery-ui-1.10.2.custom.min.js"></script>  
    <script src="js/theme.js"></script>
	<script src="js/bootbox.min.js"></script>
		
    <script type="text/javascript">
	var oneUser;
	var res;
	var sKeyVal;
	function JumpTODevOAMPage(username,idnum)
	{
		if(username == null || username == "" || username == 'undefined'){
		alert("设备NID为空");
		return;
		}
		parent.Reload_devOAM(username,idnum);
				
	}
	function JumpTOCreatuserPage()
	{
		parent.Reload_CreatUser();
	}
function responseHandler(res) {
	return {
	"rows": res.data.rows,
	"total": res.data.total
	};
}
//传递的参数
function queryParams(params) {
	return {
		pagesize: params.limit,
		page: params.pageNumber,
		sKey: sKeyVal
	};
}

function getLicenseFormatter(value, row, index) {
	if(row.locked == true)
		return '<button class="btn-glow success" data-toggle="button"  id="locked'+ row.id +'" onclick="GetLicenseFrom('+row.id+ ',' + row.locked+')">解冻</button>';
	else
		return '<button class="btn-flat gray" data-toggle="button" id="locked'+ row.id +'" onclick="GetLicenseFrom('+row.id+ ',' + row.locked+')">冻结</button>';
}
function jumpTodevMngFormatter(value, row, index) {
            return '<a target="mainIframe" title="点击跳转到该账户的设备管理页" onclick="JumpTODevOAMPage(\''+ row.account+ '\',\'' + row.id+'\')">' +row.account +'</a>';
}
function operateFormatter(value, row, index) {
					 return ['<ul class="actions"><li onclick="UserMng('+row.id+ ',' + index+')"><i class="table-edit" ></i></li><li class="last" onclick="DelOneUserDiv(\''+ row.id+'\')"><i class="table-delete"></i></li></ul>'
							].join('');
}
function GetLicenseFrom(pramid,pramfrozen)
{
	
	$.ajax({                 
				  
                url:'../adminMgr/org/switchOrgInfoLocked',
				type: 'GET',  
                dataType: 'json',                 
                cache: false,
				data:{id: pramid},                
				error : function() {
					
					bootbox.alert("账户冻结连接超时...", function() {
						//return;
					});				
				},    
                success: function(data){	               
					
					if(data.resultCode != '10000'){
						
						bootbox.alert(data.resultMsg, function() {					
						//return;
						});	
						
					}
					else{
						bootbox.alert(data.resultMsg, function() {
						$('#table').bootstrapTable('refresh');
						});	
												
					}
				}
            });
}
function entersearch(event) {
	if (event.keyCode == 13) {
	sKeyVal = $("#SearchUserTxt").val();
	//$("#SearchUserTxt").blur();
		/*要更改bootstrapTable的url*/
	$('#table').bootstrapTable('refresh',{url:'../adminMgr/org/searchOrgInfo'});	
	}
}
function UserMng(mngUserid,ids)
{
 var rows = $('#table').bootstrapTable('getData');
 var json = eval(rows[ids]);
 $('#userMngModal').modal('show');
 $('#userMnguserid').val(json.id);
 $("#userMngusername").val(json.account);
 $("#userMngpwd").val(json.password);
 $("#userMngprojectname").val(json.name);
 $("#userMngprojectinfo").val(json.createTime);
 
}

$('#userMngModalbtn').click(function (e) {
	 mid = $('#userMnguserid').val();
	 macc = $("#userMngusername").val();
	 mpwd = $("#userMngpwd").val();
	 mname = $("#userMngprojectname").val();
	 minfo = $("#userMngprojectinfo").val();			
	 $.ajax({  
               
                url: '../adminMgr/org/modifyOrgInfo', 
                type: 'post',  
                dataType: 'json',  
                timeout: 5000,  
                cache: false,
				data:{account: macc,password: mpwd,name: mname,id: mid},               
				error : function() {
				 
				 bootbox.alert("修改账号信息数据异常，请重新修改", function() {					
						//return;
				});	
				},    
                success: function(data){
					if(data.resultCode != '10000'){						
						
						bootbox.alert(data.resultMsg, function() {					
							//return;
						});
					}
					else{
						$('#userAddModal').modal('hide');
						bootbox.alert(data.resultMsg, function() {					
							$('#table').bootstrapTable('refresh');
						});
						
					}
					 
				}
				   
     })  
	              
});

function DelOneUserDiv(oneUser)
{
	
	$('#DelOneUserModal').modal('show');
	$("#DelOneUserModal_delbtn").attr("onclick","DelOneUser(\'"+ oneUser +"\')");
	//oneUser = oneUserCrr;
	//$("#DelOneUserModal_delbtn").bind('click',DelOneUser(oneUser));  	 
}
function DelOneUser(oneUser)
{
	
	 $.ajax({  
               
                url: '../adminMgr/org/removeOrgInfo', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{id: oneUser},
				error : function() {
				
				 bootbox.alert("删除账户数据异常", function() {					
							//return;
						});
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){					
						$('#DelOneUserModal').modal('hide');
						
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#DelOneUserModal').modal('hide'); 
						 bootbox.alert(deldata.resultMsg, function() {					
							$('#table').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}               
								   
     })  
}
$(function () {

$('#table').bootstrapTable({
	method: 'post',
	url: "../adminMgr/org/loadOrgInfoList",		
	//height: 500,
	striped: true,
	dataType: "json",
	cache: false,
	pagination: true,
	"queryParamsType": "limit",
	singleSelect: false,
	contentType: "application/x-www-form-urlencoded",
	pageSize: 10,
	pageNumber:1,
	showRefresh: false,
	showToggle: false,
	search: false, //不显示 搜索框
	showColumns: false, //不显示下拉框（选择显示的列）
	sidePagination: "server", //服务端请求
	queryParams: queryParams,
	responseHandler: responseHandler,
	
	columns: [{
                    field: 'state',
                    checkbox: true
         }, 		
		{
			field: 'id',	
			title: 'id',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		{
			field: 'name',	
			title: '工程商名称',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},		
		{
			field: 'account',	
			title: '用户名',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',
			formatter: jumpTodevMngFormatter,	
			sortable: false	
		},
		////			
		{
			title: '账户冻结',
			field: 'locked',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',	
			formatter: getLicenseFormatter,				
			sortable: false	
		},
		{
			title: '修改/删除账户',
			field: 'operate',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',	
			formatter: operateFormatter,				
			sortable: false	
		}
	]
	});
 $('#SearchUserbtn').click(function (e) {
	sKeyVal = $("#SearchUserTxt").val();	
		/*要更改bootstrapTable的url*/
	$('#table').bootstrapTable('refresh',{url:'../adminMgr/org/searchOrgInfo'});	              
});
 $("#SearchUserTxt").focus(function(){
  $("#SearchUserTxt").val("");
});
 $('#ViewAllbtn').click(function(e){
		e.preventDefault();
		$('#table').bootstrapTable('refresh',{url:'../adminMgr/org/loadOrgInfoList'});
		
	});
	$('#DeleteUserbtn').click(function(e){
		e.preventDefault();
		$('#userDeleteModal').modal('show'); 
		
	});
	$('#userDeleteModal_delbtn').click(function (e) {
	
	var ids = "";
	var rows = $('#table').bootstrapTable('getSelections');
	for (var i = 0; i < rows.length; i++) {
		ids += rows[i].id + ',';
	}
	ids = ids.substring(0, ids.length - 1);
   
	if (ids == "") {
		
		 bootbox.alert("请选择您要删除的账户！", function() {					
						return;
		});	
		//return;
	}	
	 $.ajax({  
               
                url: '../adminMgr/org/removeOrgInfo', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{id: ids},               
				error : function() {
					bootbox.alert("删除账户数据异常！", function() {					
						//return;
					});	
				 
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){					
						$('#userDeleteModal').modal('hide');
						
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#userDeleteModal').modal('hide'); 
						 bootbox.alert(deldata.resultMsg, function() {					
							$('#table').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}
				   
     })  
	              
});	
	
            function showTooltip(x, y, contents) {
                $('<div id="tooltip">' + contents + '</div>').css( {
                    position: 'absolute',
                    display: 'none',
                    top: y - 30,
                    left: x - 50,
                    color: "#fff",
                    padding: '2px 5px',
                    'border-radius': '6px',
                    'background-color': '#000',
                    opacity: 0.80
                }).appendTo("body").fadeIn(200);
            }

            var previousPoint = null;
            $("#statsChart").bind("plothover", function (event, pos, item) {
                if (item) {
                    if (previousPoint != item.dataIndex) {
                        previousPoint = item.dataIndex;

                        $("#tooltip").remove();
                        var x = item.datapoint[0].toFixed(0),
                            y = item.datapoint[1].toFixed(0);

                        var month = item.series.xaxis.ticks[item.dataIndex].label;

                        showTooltip(item.pageX, item.pageY,
                                    item.series.label + " of " + month + ": " + y);
                    }
                }
                else {
                    $("#tooltip").remove();
                    previousPoint = null;
                }
            });
			//$('.fixed-table-header').empty();
        });
	/*监听键盘事件*/
	$("#SearchUserTxt").keyup(function(){
		var searchKey = $("#SearchUserTxt").val();
		if(searchKey){
			$("#cleanBtn > i").attr("class","icon-remove");
			$("#cleanBtn").attr("onclick","cleanIput()");
		}else {
			$("#cleanBtn > i").attr("class","icon-search");
			$("#cleanBtn ").attr("onclick","");
		}
	});
	/*清空输入框*/
	function cleanIput(){
		$("#SearchUserTxt").val("");
		$("#SearchUserTxt").focus();
		$("#cleanBtn > i").attr("class","icon-search");
		$("#cleanBtn ").attr("onclick","");
	}
	</script>

</body>
</html>